<?php

if (Yii::app()->user->checkAccess("supervisor")) {
    $provider = $model->sin_FechaSalida()->search();
} else if (Yii::app()->user->checkAccess("institucion")) {
    $provider = $model->de_institucion()->sin_FechaSalida()->search();
}

$this->widget('bootstrap.widgets.TbGridView', array(
    'id' => 'patologias-niniosActivos-grid',
    'type' => 'striped condensed',
    'dataProvider' => $provider,
    'filter' => $model,
    'columns' => array(
        array(
            'name' => 'institucion',
            'header' => 'Institución',
            'value' => 'isset($data->ninios) ? $data->ninios->institucion->nombre : ""',
            'visible' => Yii::app()->user->checkAccess("admin") || Yii::app()->user->checkAccess("supervisor") ? true : false,
            'filter' => Yii::app()->user->checkAccess("admin") || Yii::app()->user->checkAccess("supervisor") ?
                    CHtml::listData(Institucion::model()->findAll(), 'id', Institucion:: representingColumn()) : "",
        ),
        array(
            'name' => 'nombreCompletoInfante',
            'value' => 'isset($data->ninios) ? $data->ninios->nombre_completo : null',
        ),
        'pregunta1',
        'pregunta2',
        'pregunta3',
        'pregunta4',
        array(
            'class' => 'CButtonColumn',
            'template' => '{view} {update} {delete}',
            'buttons' => array(
                'view' => array('label' => '<button class="btn btn-info"><i class="icon-eye-open"></i></button>',
                    'options' => array(
                        'title' => Yii::t('AweCrud.app', 'Ver'),
                    ),
                    'type' => 'raw',
                    'imageUrl' => false,
                ),
                'update' => array('label' => '<button class="btn btn-success"><i class="icon-pencil"></i></button>',
                    'options' => array(
                        'title' => Yii::t('AweCrud.app', 'Actualizar'),
                    ),
                    'type' => 'raw',
                    'visible' => Yii::app()->user->checkAccess("admin") ? 'true' : Yii::app()->user->checkAccess("institucion") ? 'true' : 'false',
                    'imageUrl' => false,
                ),
                'delete' => array(
                    'label' => '<button class="btn btn-warning"><i class="icon-trash"></i></button>',
                    'options' => array(
                        'title' => Yii::t('AweCrud.app', 'Eliminar'),
                    ),
                    'type' => 'raw',
                    'visible' => Yii::app()->user->checkAccess("admin") ? 'true' : 'false',
                    'imageUrl' => false,
                ),
            ),
            'htmlOptions' => array(
                'width' => Yii::app()->user->checkAccess("institucion") ? '100' : Yii::app()->user->checkAccess("admin") ? '140' : '100',
            ),
        ),
    ),
));
